﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DoAn_BumTruong_DesignPattern
{
    class ModuleProxy : Abstract
    {
        ModuleController mdctrl;
        public List<Modules> ListAll()
        {
            if (mdctrl == null)
            {
                mdctrl = new ModuleController();
            }
            return mdctrl.SelectAll();
        }
        public List<Modules> Paging(string page, out int howManyPage)
        {
            if (mdctrl == null)
            {
                mdctrl = new ModuleController();
            }
            return mdctrl.Paging(page, out howManyPage);
        }
        public Modules SingleModule(string moduleID)
        {
            if (mdctrl == null)
            {
                mdctrl = new ModuleController();
            }
            return mdctrl.SingleModule(moduleID);
        }

        //Add module
        public override bool Add(object o)
        {
            try
            {
                if (mdctrl == null)
                    mdctrl = new ModuleController();
                return mdctrl.Add(o);
            }
            catch (Exception)
            {
                throw;
            }
        }

        //Delete module
        public override bool Delete(object o)
        {
            try
            {
                if (mdctrl == null)
                    mdctrl = new ModuleController();
                return mdctrl.Delete(o);
            }
            catch (Exception)
            {
                throw;
            }
        }

        //Update module
        public override bool Update(object o)
        {
            try
            {
                if (mdctrl == null)
                    mdctrl = new ModuleController();
                return mdctrl.Update(o);
            }
            catch (Exception)
            {
                throw;
            }
        }

        //Update Active
        public bool UpdateActive(int id, bool state)
        {
            try
            {
                if (mdctrl == null)
                    mdctrl = new ModuleController();
                return mdctrl.UpdateActive(id, state);
            }
            catch (Exception)
            {
                throw;
            }
        }

        //Update Position
        public bool UpdatePosition(int id, int pos)
        {
            try
            {
                if (mdctrl == null)
                    mdctrl = new ModuleController();
                return mdctrl.UpdatePosition(id, pos);
            }
            catch (Exception)
            {
                return false;
            }
        }

        //Update OrderNo
        public bool UpdateOrderNo(int id, int orderNo)
        {
            try
            {
                if (mdctrl == null)
                    mdctrl = new ModuleController();
                return mdctrl.UpdateOrderNo(id, orderNo);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}